package com.x.Part1_linearArray;
/**
 * ClassName: LinearArray1
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2023/9/12 14:56
 */
public class LinearArray1 {
    public static void main(String[] args) {
        //数组的声明
        double[] prices;
        //数组的初始化(静态初始化)
        prices = new double[]{20.32, 43.21, 54.21};

        //写法一
        //String[] foods;
        //foods =new String[]{"拌海蜇", "龙须菜", "杏仁露"};

        //写法二
        //数组初始化(动态初始化)
        String[] foods = new String[3];
        foods[0] = "拌海蜇";
        foods[1] = "龙须菜";
        foods[2] = "杏仁露";

        //数组长度: length
        System.out.println(foods.length);
        System.out.println(prices.length);

        //遍历数组
        for (int i = 0; i < foods.length; i++){
            System.out.println(foods[i]);
        }

        for (int i = 0; i < prices.length; i++){
            System.out.println(prices[i]);
        }

        //动态初始化
        int[] a = new int[3];
        //int型数组默认初始化值为0
        System.out.println(a[0]);//输出0

        //整型元素默认初始化值为0
        //浮点型元素默认初始化值为0.0

        //字符型元素默认初始化值为0 (或理解为‘\u0000’)
        char[] b = new char[2];
        if (b[0] == 0)
            System.out.println(b[0] + "\t12345");
        if (b[0] == '0')
            System.out.println(b[0] + "\t12345");

        //boolean类型数组默认初始值为false
        boolean[] f = new boolean[3];
        for (int i = 0; i < f.length; i++)
            System.out.println(f[i]);

        //引用数据类型数组元素默认初始化值为null
        String[] g = new String[3];
        for (int i = 0; i < g.length; i++)
            System.out.println(g[i]);

    }
}
